
#include <BElement>
#include "member_BElement.h"

using namespace BWE;

#define member					(*(member_BElement*)_ptr)
#define member_allocate()		_ptr = new member_BElement(this)
#define member_release()		delete (member_BElement*)_ptr

extern BArray<GLuint>	UnusedTextureObjects;
extern BArray<GLuint>	UnusedFrameBufferObjects;
extern BArray<GLuint>	UnusedRenderBufferObjects;
extern BArray<GLuint>	UnusedProgramObjects;
extern BArray<GLuint>	UnusedShaderObjects;
extern BArray<GLuint>	UnusedListObjects;

BElement::BElement()
{
	member_allocate();
}
BElement::BElement(Primitive primitive, int first, int count)
{
	member_allocate();
	member.primitive = primitive;
	member.first = first;
	member.count = count;
	member.dirtyList = true;
}
BElement::BElement(Primitive primitive, BIndexArray* indices)
{
	member_allocate();
	member.primitive = primitive;
	member.first = 0;
	if (indices)
	{
		member.count = indices->size();
		member.indices = indices;
		member.dirtyList = true;
	}
}
BElement::BElement(const BElement& other)
{
	member_allocate();
	member.primitive = other.primitive();
	member.first = other.first();
	member.count = other.count();
	member.indices = other.indices();
	member.pieces = other.pieces();
}
BElement::~BElement()
{
	if (member.listName)
	{
		UnusedListObjects.append(member.listName);
		member.listName = 0;
	}
	member_release();
}

void BElement::set(Primitive primitive, int first, int count)
{
	member.primitive = primitive;
	member.first = first;
	member.count = count;
	member.dirtyList = true;
}

void BElement::setPrimitive(Primitive primitive)
{
	if (member.primitive != primitive)
	{
		member.primitive = primitive;
		member.dirtyList = true;
	}
}
Primitive BElement::primitive() const
{
	return member.primitive;
}

void BElement::setFirst(int first)
{
	if (first < 0)
		first = 0;
	if (member.first != first)
	{
		member.first = first;
		member.dirtyList = true;
	}
}
int BElement::first() const
{
	return member.first;
}

void BElement::setCount(int count)
{
	if (count < 0)
		count = 0;
	if (member.count != count)
	{
		member.count = count;
		member.dirtyList = true;
	}
}
int BElement::count() const
{
	return member.count;
}

void BElement::setIndices(BIndexArray* indices)
{
	member.indices = indices;
	member.dirtyList = true;
}
BIndexArray* BElement::indices() const
{
	return member.indices;
}

void BElement::setPieces(BPieceArray* pieces)
{
	member.pieces = pieces;
	member.dirtyList = true;
}
BPieceArray* BElement::pieces() const
{
	return member.pieces;
}
